<?
/*
Bitsand - a web-based booking system for LRP events
Copyright (C) 2006, 2007 Russell Peter Phillips

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

include ('inc_head_db.php');
include ('inc_head_html.php');
?>

<?
if ($_POST ['btnSubmit'] != '') {
	//Check password is at least 6 characters, and both fields match
	$sWarn = '';
	if (strlen ($_POST ['txtPassword']) < 6)
		$sWarn .= "The password must be at least 6 characters<br>\n";
	if ($_POST ['txtPassword'] != $_POST ['txtPassword2'])
		$sWarn .= "The passwords entered did not match<br>\n";
	//Set span class to warn
	if ($sWarn != '')
		$sWarn = "$sWarn";
	if ($sWarn == '') {
		//Run update query & set message
		$sHashPass = sha1 ($_POST ['txtPassword'] . PW_SALT);
		$sql = "UPDATE players SET plPassword = '$sHashPass' WHERE plPlayerID = $PLAYER_ID";
		$result = mysqli_query ($link, $sql);
		$sGreen = "Password reset. Next time you log in, you will have to use your new password";
	}
}
?>

<h1><?=TITLE?> - Change Password</h1>

<p>
<?
if ($sWarn != '')
	echo "<p class = 'warn'>\n$sWarn</p>\n";
if ($sGreen != '')
	echo "<p class = 'green'>\n$sGreen</p>\n";
?>
You can change your password using the form below:
<p>

<form action = 'change_password.php' method = 'post' onsubmit = 'return form_check ()'>
<table align = 'center'>
<tr>
<td>New password:</td>
<td><input name = 'txtPassword' class = 'text' type = 'password'></td>
</tr>
<tr>
<td>Confirm new password:</td>
<td><input name = 'txtPassword2' class = 'text' type = 'password'></td>
</tr>
<tr><td>&nbsp;</td></tr><tr>
<td colspan = '2' class = 'mid'><input type = 'submit' name = 'btnSubmit' value = 'Change password'>&nbsp;
<input type = 'reset' value = "Reset form"></td>
</tr>
</table>
</form>

<?
include ('inc_foot.php');
?>
